<?php
class Reponse {

	public $id;
	public $description;
		
	
	
	public function __construct($id='') {
		if($id != ''){
			$this->id = $id;
			$this->load();
		}
	}

	public function load() {
		if(isset($this->id)){
			$db = Database::getInstance();
			$sql= 'SELECT idReponse, 
                                      description,
                                      date
                               FROM reponse
			       WHERE idReponse = "'.$this->id.'"';					
						  
						  
			if ($result = $db->fetch($sql)){				
				$this->description = $result[0]['description'];					
				
				return true;
			}
			return false;	
		}
	}
	
	public function __toString(){
		return $this->description.' ';
	
	}
	
	
	public static function getAll() {
		$i=0;
		$array = null;
		
		$db = Database::getInstance();
			$sql= 'SELECT idReponse,
                                      description,
                                      date						  
				FROM reponse';					
						  
						  
			if ($result = $db->fetch($sql)){	
				foreach($result as $row){ 
					$tmp_reponse = new Reponse();					
					$tmp_reponse->description = $row['description'];
					$tmp_reponse->date = $row['date'];
					
					$array[] =  $tmp_reponse;
				}		
			}
			return $array;			
	}
	
		
	public function addReponse($description){
	/* On �chappe les information ins�r�es par l'utilisateur*/
		
		$db = Database::getInstance();
		$sql= 'INSERT INTO `reponse` (
		`idReponse` ,
		`description` ,
                `date`
		)
		VALUES 
		(
		NULL ,
		"'.$description.'",		
		CURRENT_TIMESTAMP
		)';
		
		if($db->exec($sql)){
			return $db->lastInsertId();
		}
		
		return false;
		
	}
	
	
}

?>